#include <iostream>

using namespace std;

typedef long long LL;

const int N = 3e5 + 10;
LL a[N], n, T;
LL p = 998244353;

int main()
{
	cin >> T;
	while(T--)
	{
		cin >> n;
		for(int i = 1; i <= n; i++) cin >> a[i];
        
		LL ret = 1, num = n - a[1]; 
		for(int i = 2; i <= n; i++)
		{
			if(a[i] == a[i - 1]) 
            {
                ret = (ret * num) % p;
                num--;
            }
            else if(a[i] > a[i - 1])
            {
                cout << 0 << endl;
                return;
            }
			else
            {
                num += a[i - 1] - a[i] - 1;
            }
			
		}
		cout << ret << endl;
	}
	return 0;
} 
